// member/pages/offlineOrderDetails/offlineOrderDetails.js
let myRequest = require('../../../common/script/myRequest.js');
let api = require('../../../common/script/api.js');
let wxbarcode = require("../../../utils/wxbarcode/index")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
    return_code: "",
    total: ""
  },
  getData(order_sn) {
    const that = this;
    let data = {
      order_sn
    }
    wx.showLoading({
      title: '加载中...',
    })
    myRequest.EasyHttp.post(api.reqUrls.getOfflineOrderDetailList, data).then(res => {
      wx.hideLoading();
      if (res.data.status == 1) {
        that.setData({
          listData: res.data.result.good_list,
          return_code: res.data.result.order.return_code,
          total: res.data.result.order.money
        })
        if(res.data.result.order.return_code){
          that.barCode(res.data.result.order.return_code)

        }
      }
    })
  },
  barCode(code) {
    const query = this.createSelectorQuery()
    query.select('#barcode').fields({
      node: true,
      size: true
    }).exec(res => {
      const canvas = res[0].node
      const ctx = canvas.getContext('2d')
      const width = res[0].width
      const height = res[0].height
      // 初始化画布大小
      const dpr = wx.getWindowInfo().pixelRatio
      canvas.width = width * dpr
      canvas.height = height * dpr
      ctx.scale(dpr, dpr)
      wxbarcode.barcode(ctx, {
        code: code,
        width: 750,
        height: 120,
        fgcolor: '#222222',
        bgcolor: '#ffffff',

      });
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    that.getData(options.order_sn)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})